﻿<!DOCTYPE html>
<html>
<head>
   <title>Running Matlab with Simulation Workbench on Linux</title>
   <meta name="generator" content="Help & Manual">
   <meta name="keywords" content="">
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <link type="text/css" href="default.css" rel="stylesheet">
   <link type="text/css" href="custom.css" rel="stylesheet">
   <script type="text/javascript" src="nsh.js"></script>
   
<!-- non-scrolling headers for CHM and browser-based help, local styles-->
<style TYPE="text/css" media="screen"> 
   <!-- 
   body {    
      margin:0; 
      padding:0; 
      overflow: auto; 
      background: #edede9; 
   } 
   #idheader { 
      width:100%; 
      height:auto; 
      padding: 0; 
      margin: 0;     
} 
    #idheaderbg  {
    background: #E40A00; 
}
#idheadernowrap  {
    white-space:nowrap; 
}
    ul {list-style-type: lower-roman}
   -->
   </style>
   
<style TYPE="text/css" MEDIA="print">
<!--
/* Hide navigation links and add space between header
     and text in the printed version. Not valid for eBooks. */
#idnav { display:none;	 }
.topichead { padding: 5px 5px 20px 5px; }
-->
</style>   
   <script type="text/javascript" src="jquery.js"></script>
   <script type="text/javascript" src="helpman_settings.js"></script>
   <script type="text/javascript" src="helpman_topicinit.js"></script>

   <script type="text/javascript">
     HMSyncTOC("index.html", "vbk_tut_running_matlab_with_v2.htm");
   </script>
   <script type="text/javascript" src="highlight.js"></script>
   <script type="text/javascript">
     $(document).ready(function(){highlight();});
   </script>
</head>
<body>

<!--ZOOMSTOP-->

<div id="idheader" >
<div id="idheaderbg">
<table width="100%" border="0" cellspacing="0" cellpadding="0" 
       style="margin: 0px; color: #D7D7D7;">

  <tr valign="middle">
    <td align="left" valign="middle" class="topichead">
    <!--<div id="idheadernowrap">-->
    <p class="crumbs" id="idnav"><b>Navigation:</b>&nbsp;
   
   VI-DriveSim 19.2 on Linux &gt; <a href="drivesim_tut_tutorials.htm">VI-DriveSim 19.2 Tutorials</a> &gt; Running Matlab with VI-DriveSim&nbsp;&gt;</p>
      <h1 class="p_Heading1" style="page-break-after: avoid;"><span class="f_Heading1">Running Matlab with Simulation Workbench on Linux RTOS</span></h1>

    <!--</div>-->
    </td>
    <td align="right" width="180" valign="middle" class="topichead" id="idnav">
    <div id="idheadernowrap">
    <a href="javascript: print();"
    		onmouseover="document.images.prntr.src='print_a.png'" 
        onmouseout="document.images.prntr.src='print_n.png'"
        ><img name="prntr" border="0" alt="Print this Topic" title="Print this Topic" src="print_n.png"
        ></a>&nbsp;&nbsp;
     <a href="drvsim_inst_vi-graphsim-19-configuration.htm"
        onmouseover="document.images.prev.src='back_a.png'" 
        onmouseout="document.images.prev.src='back_n.png'"
        ><img name=prev src="back_n.png" border=0 alt="Previous page"
        ></a><a href="drivesim_tut_tutorials.htm"
        onmouseover="document.images.main.src='top_a.png'" 
        onmouseout="document.images.main.src='top_n.png'"><img name=main src="top_n.png" border=0 alt="Return to chapter overview"
        ></a><a href="drvsim_tut_running_scaner_studio_with_vi-.htm"
        onmouseover="document.images.next.src='next_a.png'" 
        onmouseout="document.images.next.src='next_n.png'"><img name=next src="next_n.png" border=0 alt="Next page"
        ></a>
    </div>
    </td>
  </tr>
</table>
</div>

<!-- The following code displays Expand All/Collapse All links  below the header in topics containing toggles -->
  

</div>  



<div id="idcontent"><div id="innerdiv"> 
<!--ZOOMRESTART-->
<p class="p_Normal">As for VI-CarRealTime offline simulation, it is possible to run a cosimulation between VI-DriveSim and Matlab/Simulink. The same Matlab/Simulink model created for the offline simulation can be used for the cosimulation with VI-DriveSim, after a few small changes.</p>
<p class="p_Normal">The Matlab/Simulink model can be compiled from the Windows Machine on the Linux Machine, with the help of the SimWB Toolkit. It is so necessary to install the SimWB Toolkit on the Windows Machine where the Simulink is saved. The installation will add the SimWB libraries to the Matlab path and all the needed menus to use the RTDB Blocks.</p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal"><span style="font-weight: bold;">NOTE:</span> <span style="font-weight: bold;">please check the compatible versions of Matlab/Simulink with your SimlationWorkBench version</span>.</p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal">After you have correctly installed the SimWB Toolkit, you can open your Matlab/Simulink model that runs with VI-CarRealTime.</p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal"><span style="font-weight: bold;">NOTE: Be sure that the abort time of the Matlab/Simulink model is set to &quot;inf&quot;, otherwise the simulation will be stop after reaching the abort time.</span></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_006" width="570" height="458" style="margin:0px auto 0px auto;width:570px;height:458px;border:none" src="drvsim_matlab_006.png"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">To compile it on the Linux Machine, follow these steps:</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>delete the VI-CarRealTime mex.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_007" width="570" height="458" style="margin:0px auto 0px auto;width:570px;height:458px;border:none" src="drvsim_matlab_007.png"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Go under <span style="font-style: italic;">SimWB -&gt; Libraries -&gt; RTDB Block Lib</span>.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_008" width="574" height="180" style="margin:0px auto 0px auto;width:574px;height:180px;border:none" src="drvsim_matlab_008.png"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Drag and drop all the I/O blocks that you may need (accordingly with your Matlab version).</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_009" width="622" height="348" style="margin:0px auto 0px auto;width:622px;height:348px;border:none" src="drvsim_matlab_009.jpg"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Connect them to your model, as if you were connecting the VI-CarRealTime mex.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_010" width="407" height="408" style="margin:0px auto 0px auto;width:407px;height:408px;border:none" src="drvsim_matlab_010.jpg"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Open Simulation Workbench, pick the RTDB that you want to use and load it by clicking on the &quot;Load the selected RTDB&quot; button.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_011" width="635" height="318" style="margin:0px auto 0px auto;width:635px;height:318px;border:none" src="drvsim_matlab_011.jpg"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Go under Analog Points, look for the channels you have to connect your blocks and copy their names.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_014" width="755" height="530" style="margin:0px auto 0px auto;width:755px;height:530px;border:none" src="drvsim_matlab_014.jpg"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Rename the blocks and their variables with the correct name of the RTDB variable. </p><p class="p_Normal"><span style="font-weight: bold;">NOTE: If the variable has a different name respect to the VI-CarRealTime RTDB channel, then a new channel will be added in the RTDB when the Simulink will be compiled, but the model will not work as expected.</span></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_013" width="877" height="650" style="margin:0px auto 0px auto;width:877px;height:650px;border:none" src="drvsim_matlab_013.jpg"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>From Simulink, go under SimWB -&gt; preferences and set them as follow.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_ML_toolkit_1" width="431" height="377" style="margin:0px auto 0px auto;width:431px;height:377px;border:none" src="drvsim_ml_toolkit_1.png"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_ML_toolkit_2" width="431" height="377" style="margin:0px auto 0px auto;width:431px;height:377px;border:none" src="drvsim_ml_toolkit_2.png"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_ML_toolkit_3" width="431" height="377" style="margin:0px auto 0px auto;width:431px;height:377px;border:none" src="drvsim_ml_toolkit_3.png"/></p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>From Simulink, go under SimWB -&gt; Toolkit, set the correct Host name (IP of the Concurrent Machine) and click on connect.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_ML_toolkit_4" width="403" height="419" style="margin:0px auto 0px auto;width:403px;height:419px;border:none" src="drvsim_ml_toolkit_4.png"/></p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Click on RTDB creator, select from the RTDB list the one you are using on Simulation Workbench and click on &quot;Create and upload RTDB&quot;. <span style="font-weight: bold;">When asked, click on &quot;Update/Append&quot;.</span></p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_ML_toolkit_5" width="403" height="419" style="margin:0px auto 0px auto;width:403px;height:419px;border:none" src="drvsim_ml_toolkit_5.png"/></p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>When done, check in the Matlab command window if the RTDB has been successfully appended.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_018" width="751" height="328" style="margin:0px auto 0px auto;width:751px;height:328px;border:none" src="drvsim_matlab_018.jpg"/></p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Click on Code Generator, select from the RTDB list the one you are using on Simulation Workbench and click on &quot;Generate, Export, and Make&quot;.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_ML_toolkit_6" width="403" height="419" style="margin:0px auto 0px auto;width:403px;height:419px;border:none" src="drvsim_ml_toolkit_6.png"/></p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>When done, check in the Matlab command window if the code has been successfully generated.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_020" width="922" height="444" style="margin:0px auto 0px auto;width:922px;height:444px;border:none" src="drvsim_matlab_020.jpg"/></p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal"><span style="font-weight: bold;">NOTE. </span>If the name of the Simulink model is too long, the compilation will fail; if this happen, save the Simulink model with a shorter name, and try recompiling.</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Restart Simulation Workbench, then create a new test and pick the just created process from the list as shown below.</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_Matlab_021" width="875" height="563" style="margin:0px auto 0px auto;width:875px;height:563px;border:none" src="drvsim_matlab_021.jpg"/></p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;">&nbsp;</p>
<p class="p_Normal">Please refer to <a href="drvsim_inst_creating-a-test-with-simwb.htm" class="topiclink">this chapter</a> for further information about how to setup tests and sessions with Simulation Workbench.</p>
<p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 0px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Now, in order to effectively write on the channels you want with the Simulink model, you need to activate them from VI-DriveSim GUI, in the Vicrt Inputs window. In this example, since we are writing on the Damper Forces, we will need to write on the following channels:</p><p class="p_Normal">&nbsp;</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 49px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#9642;</span>Main_Damper.Activity_Flag_L1/L2/R1/R2 - necessary to deactivate the internal dampers of VI-CarRealTime, the value of these channels must be set to 0</p><p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 49px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#9642;</span>Main_Damper.Force_L1/L2/R1/R2 - by checking the box, the model will receive the forces calculated into the Simulink model</p><p class="p_Normal" style="text-indent: 46px; margin: 0px 0px 0px 3px;">&nbsp;</p>
<p class="p_Normal" style="text-align: center;"><img alt="drvsim_input_Simulink" width="349" height="382" style="margin:0px auto 0px auto;width:349px;height:382px;border:none" src="drvsim_input_simulink.png"/></p>
<p class="p_Normal" style="text-indent: 46px; margin: 0px 0px 0px 3px;">&nbsp;</p>
<p class="p_Normal" style="text-indent: -1px; margin: 0px 0px 0px 3px;"><span style="font-weight: bold;">NOTE: if the Activity Flag is not set to 0, and the Main_Damper.Force_** are activated in the VI-crt Inputs, the total forces on the dampers will be the sum of the ones calculated in VI-CarRealTime and the ones calculated from the Simulink model!!</span></p>
<p class="p_Normal" style="text-indent: -1px; margin: 0px 0px 0px 3px;">&nbsp;</p>
<p class="p_Normal" style="text-indent: -1px; margin: 0px 0px 0px 3px;"><span style="font-weight: bold;">TIP: </span>in the Simulink model you can write also on the Activity Flag channels and set their values with a parameter. If you also set a parameter to activate/deactivate the active dampers of the Simulink, you can switch to active/passive dampers in realtime during the simulation, without the need of stopping and restarting the simulation. Those parameters will be tunable from SimWB/RealTime Viewer/Parameters.</p>
<p class="p_Normal" style="text-indent: -1px; margin: 0px 0px 0px 3px;">&nbsp;</p>
<p class="p_Normal" style="text-indent: -1px; margin: 0px 0px 0px 3px;">To clarify:</p>
<p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 26px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Activity flag = 0 - Active Dampers = 1 --&gt; Damper forces coming ONLY from the Simulink</p><p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 26px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Activity flag = 1 - Active Dampers = 0 --&gt; Damper forces coming ONLY from VI-CarRealTime</p><p style="text-align: justify; text-indent: 0px; padding: 0px 0px 0px 13px; margin: 0px 0px 0px 26px;"><span style="font-size:10pt; font-family: 'Arial Unicode MS','Lucida Sans Unicode','Arial';color:#000000;display:inline-block;width:13px;margin-left:-13px">&#8226;</span>Activity flag = 1 - Active Dampers = 1 --&gt; Damper forces coming both from VI-CarRealTime and Simulink model</p><p class="p_Normal">&nbsp;</p>
<p class="p_Normal">The last combination can be used for example for an ESP controller that adds brake pressure to the internal braking system of the vehicle.</p>
<p class="p_Normal">&nbsp;</p>
<p class="p_Normal">&nbsp;</p>

<!--ZOOMSTOP-->
</div></div>
<script type="text/javascript"> 
<!-- 
var lastSlashPos = document.URL.lastIndexOf("/") >
document.URL.lastIndexOf("\\") ? document.URL.lastIndexOf("/") :
document.URL.lastIndexOf("\\");
if( document.URL.substring( lastSlashPos + 1, lastSlashPos + 4
).toLowerCase() != "~hh" )
{
    nsrInit();
}
--> 
</script> 
</body>
</html>
